<?php

/**
 * Dicfro
 *
 * PHP 5
 *
 * @category   DicFro
 * @package    View
 * @subpackage Scripts_Information
 * @author     Michel Corne <mcorne@yahoo.com>
 * @copyright  2015 Michel Corne
 * @license    http://opensource.org/licenses/gpl-3.0.html GNU GPL v3
 */

?>

<h1 class="title"><?=$this->translate('Dictionaries search test');?></h1>

<?php foreach($this->results as $results):?>

  <?php if (! empty($results['result'])):?>

    <?php foreach($results['result'] as $index => $result):?>

      <div class="test-result">

        <?php if ($index):?>
          <?=$results['name'];?> (#<?=$index;?>):
        <?php else:?>
          <?=$results['name'];?>:
        <?php endif;?>

        <?php if (! $result):?>
          <span class="orange">Not tested</span>

        <?php elseif (! isset($results['expected']) or ! isset($results['expected'][$index])):?>
          <span class="orange">
              Please check the result! Keep or remove tests/search/<?=$results['id'];?> accordingly.
          </span>

        <?php elseif ($result != $results['expected'][$index]):?>
          <span class="red">
              Error! Fix and/or remove &quot;tests/search/<?=$results['id'];?>&quot; accordingly.
          </span>

        <?php else:?>
          <span class="green">Test OK.</span>

        <?php endif;?>

        <?php if ($result):?>
          <a href="javascript:hideOrDisplay('<?=$results['id'];?>-<?=$index;?>')">See details</a>.
          <pre class="test-result" id="<?=$results['id'];?>-<?=$index;?>">
Test result:
<?=preg_replace('~^Array\n\(\n(.+?)\n\)\n$~is', '$1', print_r($result, true));?>

Expected result:
<?=preg_replace('~^Array\n\(\n(.+?)\n\)\n$~is', '$1', print_r($results['expected'][$index], true));?>
          </pre>
        <?php endif;?>

      </div>

    <?php endforeach;?>

  <?php else:?>

    <div class="test-result">
      <?=$results['name'];?>:
      <span class="orange">Not tested !</span>
    </div>

  <?php endif;?>

<?php endforeach;?>
